# 自定义过滤器
import functools

from flask import session, g

from info.models import User


def do_index_class(index):
    if index == 1:
        return 'first'
    elif index == 2:
        return 'second'
    elif index == 3:
        return 'third'
    else:
        return ''



# 定义装饰器用来判断的用的登录状态
def set_func(f):
    @functools.wraps(f)
    def call_func(*args, **kwargs):
        # 获取到当前登录用户的id
        user_id = session.get('user_id')
        user = None
        if user_id:
            user = User.query.get(user_id)

        g.user = user
        return f(*args, **kwargs)
    return call_func